package com.example.liunanxin.lnx226ordering.model;

import com.example.liunanxin.lnx226ordering.beans.RegisterBean;
import com.example.liunanxin.lnx226ordering.iface.RegisterListener;
import com.example.liunanxin.lnx226ordering.iface.Registeriface;
import com.example.liunanxin.lnx226ordering.retrofitservice.RegisterService;
import com.example.liunanxin.lnx226ordering.url.Url;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class RegisterModel implements Registeriface {
    private Retrofit retrofit;

    public RegisterModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl(Url.USERURL)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getRegisterResult(String username, String userpass,String mobilenum,String address, final RegisterListener registerListener) {
        RegisterService registerService=retrofit.create(RegisterService.class);
        Call<RegisterBean> call=registerService.getsuccess(username,userpass,mobilenum,address);
        call.enqueue(new Callback<RegisterBean>() {
            @Override
            public void onResponse(Call<RegisterBean> call, Response<RegisterBean> response) {

                if (response.isSuccessful()&response!=null){
                    registerListener.onResponse(response.body());
                }
                else registerListener.onFail("onrespons fail");
            }

            @Override
            public void onFailure(Call<RegisterBean> call, Throwable t) {
                registerListener.onFail(t.toString());

            }
        });

    }
}
